package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.dubbo.dao.SettingsDao;
import com.itheima.model.domain.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsDao settingsDao;

    @Override
    public Settings findById(Long usedId) {
        LambdaQueryWrapper<Settings> lqw = Wrappers.lambdaQuery(Settings.class);
        lqw.eq(Settings::getUserId, usedId);
        Settings settings = settingsDao.selectOne(lqw);
        return settings;
    }

    @Override
    public void saveSettings(Settings settings) {
        settingsDao.insert(settings);
    }

    @Override
    public void updateSettings(Settings settings) {
        LambdaQueryWrapper<Settings> lqw = Wrappers.lambdaQuery(Settings.class);
        lqw.eq(Settings::getUserId, settings.getUserId());
        settingsDao.update(settings, lqw);
    }



}
